package executors.completable.future;

import java.util.concurrent.*;

public class CompleteTest001 {
  public static void main(String[] args) {
    CompletableFuture<String> flushOKFuture = new CompletableFuture<>();
    
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.execute(() -> {
      System.out.println("此时是一个刷盘的线程 ... ");
      try {
        TimeUnit.SECONDS.sleep(3);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
      
      flushOKFuture.complete("ok");
    });
    
    ExecutorService executorService1 = Executors.newSingleThreadExecutor();
    executorService1.execute(() -> {
      System.out.println("mq 同步返回");
      try {
        System.out.println(flushOKFuture.get());
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      } catch (ExecutionException e) {
        throw new RuntimeException(e);
      }
    });
    
    while (true) {
    }
  }
}
